package com.shipwe.loans.ui.factory

import android.util.SparseArray
import androidx.fragment.app.Fragment
import com.shipwe.loans.base.BaseFragment
import com.shipwe.loans.ui.fragment.FragmentHome
import com.shipwe.loans.ui.fragment.FragmentLuckyDraw
import com.shipwe.loans.ui.fragment.FragmentOrderRepay

class MainFragmentFactory {

    companion object {
        private val fragments by lazy { SparseArray<BaseFragment?>() }
        @JvmStatic
        fun create(position: Int): Fragment {
            var fragment = fragments.get(position)
            if (fragment == null) {
                fragment = when (position) {
                    0 -> FragmentHome()
                    1 -> FragmentOrderRepay()
                    else -> FragmentLuckyDraw()
                }
                fragments.put(position, fragment)
            }
            return fragment
        }
        @JvmStatic
        fun clear() {
            fragments.clear()
        }
    }
}